// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import $ from 'jquery'
import 'bootstrap/dist/css/bootstrap.min.css'
import 'bootstrap/dist/js/bootstrap.min'
import MintUI from 'mint-ui'
import 'mint-ui/lib/style.css'
import global_var from './components/common/Global'

Vue.config.productionTip = false
Vue.use(MintUI)
Vue.prototype.GLOBAL = global_var//挂载到Vue实例上面

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})

router.beforeEach((to, from, next) => {
  //to即将进入的目标路由对象，from当前导航正要离开的路由， next  :  下一步执行的函数钩子
  if(to.path === '/login'||to.path ==='/register')  { // 如果即将进入登录路由或者注册路由，则直接放行
    next()
  } else { //进入的不是登录路由
    if(to.meta.requiresAuth && !sessionStorage.getItem('accessToken'))
      {
        next({ path: '/login' })
      } else { //下一跳路由需要登录验证，并且还未登录，则路由定向到  登录路由
      next()
    }
  }  //如果不需要登录验证，或者已经登录成功，则直接放行
})
